//Ta Duc Viet
//Bang chuyen doi F - C 
#include <iostream>
#include <iomanip>
using namespace std;

double celsius_of(int fahr);
double absolute_value_of(int fahr);
void print_preliminary_message();
void input_table_specifications(int &lower, int &upper, int &step);
void print_message_echoing_input(int lower, int upper, int step);
void print_table(int lower, int upper, int step);

int main() {	
	int lower = 0; /* the lowest Fahrenheit entry in the table */
	int upper = 0; /* the highest Fahrenheit entry in the table */
	int step = 1;  /* difference in Fahrenheit between entries */

	/* print a message explaining what the program does: */
	print_preliminary_message();
	cout << endl;
	/* prompt the user for table specifications in Fahrenheit: */
	input_table_specifications(lower, upper, step);
    cout << endl;
	/* print appropriate message including an echo of the input: */
	print_message_echoing_input(lower, upper, step);
	cout << endl;
	/* Print the table (including the column headings): */
	print_table(lower, upper, step);
    system("pause");
	return 0;
}

/* FUNCTION TO CONVERT FAHRENHEIT TO CELSIUS */
double celsius_of(int fahr)
{
	return (static_cast<double>(5)/9) * (fahr - 32);
}
/* END OF FUNCTION */

/* FUNCTION TO CONVERT FAHRENHEIT TO ABSOLUTE VALUE */
double absolute_value_of(int fahr)
{
	return ((static_cast<double>(5)/9) * (fahr - 32)) + 273.15;
}
/* END OF FUNCTION */

void print_preliminary_message(){
    cout << "Chuong trinh chuyen doi nhiet do" << endl;
    }
    
void input_table_specifications(int &lower, int &upper, int &step){
    cout << "Hay nhap vao nhiet do thap nhat (do Fahrenheit): ";
    cin >> lower;
    cout << "Hay nhap vao nhiet do cao nhat: ";
    cin >> upper;
    cout << "Hay nhap vao khoang cach nhiet do giua cac hang: ";
    cin >> step;
    }
    
void print_message_echoing_input(int lower, int upper, int step){
    cout << "Bang chuyen doi nhiet do tu " << lower << " Fahrenheit den " << upper << " Fahrenheit, voi moi khoang cach " << step << " Fahrenheit:" << endl;
    }
    
void print_table(int lower, int upper, int step){
    cout << fixed << setprecision (2);
    cout << setw(15) << "Fahrenheit" << setw(15) << "Celsius" << setw(20) << "Absolute Value" << endl;
    cout.setf (ios::left);
    for ( lower; lower <= upper; lower = lower + step){
        cout << "         " << setw(15) << lower << setw(15) << celsius_of (lower) << setw(20) << absolute_value_of (lower) << endl;
        }
    }

